<template>
	<view class="new-good">
		<view class="tab-list">
			<u-tabs :list="tabList" :current="current" @change="changeTab" active-color="#f12f16"></u-tabs>
		</view>
		<goodsList :res="goodsList" :keyword="keyword" :showtime="true" />
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import {
		getStoreList,
		getAllTemplate
	} from "@/api/store";
	import {
		getGoodsList,
		getGoodsRelated,
		getFg
	} from '@/api/goods.js';
	import goodsList from '@/components/m-goods-list/list.vue';
	export default {
		data() {
			return {
				goodsList: [],
				keyword: '',
				loadingType: 'more', //加载更多状态
				current: 0,
				topValue: 0,
				tabList: [],
				pageDataId: '',
				empty: false,
				params: {
					pageNumber: 1,
					pageSize: 10,
					pageDataId: '',
					keyword: '',
					sort: "createTime",
					order: "desc",
					today: 1
				},
				today: 1,
			}
		},
		components: {

			goodsList
		},
		onReachBottom() {
			this.params.pageNumber++;
			this.loadData();
		},
		mounted() {

			// this.topValue = this.$u.sys().statusBarHeight + 44 + 'px'
			// console.log(234, this.$u.sys().statusBarHeight, this.topValue)
			this.getTemplet()
			this.loadData();
		},
		methods: {
			changeTab(index) {
				this.current = index;
				this.params.pageDataId = this.tabList[index].id
				this.params.pageNumber = 1
				this.goodsList = [];
				this.loadData()
			},
			async getTemplet() {
				const res = await getAllTemplate()
				if (res.data.message === 'success') {
					const arr = res.data.result
					const arrb = []
					arr.forEach(item => {
						item.list.forEach(row => {
							if (row.type == 1 && row.pageShow == 'OPEN')
								arrb.unshift(row);
						});
					});

					this.tabList = [{
						name: '全部',
						id: ''
					}, ...arrb]
					console.log(this.tabList);
				}
			},
			async loadData(type, loading) {
				this.loadingType = 'loading';


				//没有更多直接返回 #TODO
				let goodsList = await getGoodsList(this.params);
				if (goodsList.data.result.records.length < 10) {
					this.loadingType = 'noMore';
					this.empty = true;
				} else {
					this.empty = false;
				}
				this.goodsList.push(...goodsList.data.result.records);

				// this.initSortGoods();
				// if (this.$store.state.isShowToast) {
				// 	uni.hideLoading()
				// };
			},
		}
	}
</script>

<style lang="scss" scoped>
	.new-good {
		padding-top: 44px;
	}

	.tab-list {
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		background: #fff;
		z-index: 999;
	}
</style>